Storage.prototype.$get = function(key, defaultValue = {}) {
    const value = this[key]; // String || undefined
    return value ? JSON.parse(value) : defaultValue;
}

Storage.prototype.$set = function (key, value) {
    this[key] = JSON.stringify(value);
}


localStorage.$set('AAA', { a: 1, b: 2 });

sessionStorage.$set('AAA', { a: 5, b: 7 });

console.log(sessionStorage.$get('BBB', '1231'));